package cn.fscode.code.generator.model.req;

import cn.fscode.code.generator.model.po.TemplateConfigPO;
import cn.fscode.commons.tool.core.StringUtils;
import cn.fscode.commons.tool.core.exception.BizException;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @see TemplateConfigPO
 * @author shenguangyang
 */
@Getter
@Setter
public class TemplateConfigReq {

    private Long id;

    @NotNull(message = "不能为空")
    private Long groupId;

    private String groupName;

    /** 模板名称 */
    @NotEmpty(message = "不能为空")
    private String name;

    /**
     * 目录, 为空则是模板名称
     */
    private String folder;

    /** 文件名称 */
    @NotEmpty(message = "不能为空")
    private String fileName;

    /** 内容 */
    @NotEmpty(message = "不能为空")
    private String content;

    public String getFileName() {
        String name = StringUtils.clearBracket(fileName, '{', '}');
        if (name.lastIndexOf(".") <= 0) {
            throw new BizException("文件名必须包含后缀,eg: Service.java");
        }
        return fileName;
    }
}
